package com.example.shop.cate

import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.viewModelScope
import com.example.base.entity.CategoryEntity
import com.example.base.entity.CategoryEntityResult
import com.example.base.entity.GoodsEntityResult
import com.example.base.mvvm.BaseViewModel
import kotlinx.coroutines.launch

class CateViewModel:BaseViewModel() {
    val cateSuccess = MutableLiveData<CategoryEntityResult>()
    val cateFail = MutableLiveData<String>()
    fun cate(){
        viewModelScope.launch {
            try {
                val result = apiServer.category()
                cateSuccess.value = result
            }catch (e:Exception){
                cateFail.value = e.message
            }
        }
    }
    val goodsSuccess = MutableLiveData<GoodsEntityResult>()
    val goodsFail = MutableLiveData<String>()
    fun goods(cateId:Int,page:Int,size:Int){
        viewModelScope.launch {
            try {
                val result = apiServer.goods(cateId,page,size)
                goodsSuccess.value = result
            }catch (e:Exception){
                goodsFail.value = e.message
            }
        }
    }
}